<!--
 * @Author: suo.tianbao suo.tianbao@vpclub.cn
 * @Date: 2023-10-11
 * @LastEditors: suo.tianbao suo.tianbao@vpclub.cn
 * @LastEditTime: 2023-10-11
 * @FilePath: /element-admin/src/views/aliyun/VpProduct.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div id="purn-freelifeVDB-page">
    <!--顶部搜索栏-->
    <div class="col-md-12">
      <el-row :gutter="10">
        <el-col :span="22" :offset="1" class="clearfix">
          <el-card class="box-card">
            <template #header>
              <div class="card-header">
                <span style="font-size: 22px;">A. 标准数据表 </span>
                <el-button type="info" @click="handle_load" class="register_btn" size="small">标准值</el-button>
              </div>
            </template>
            <el-form :model="FreeVDB" label-width="140px">
              <el-row :gutter="10">
                <el-col :sm="12" :xs="12" :md="12" :lg="12" :xl="12">
                  <el-form-item label="1.1 标准数据表">
                    <el-select v-model="FreeVDB.tables" placeholder="标准数据表" size="small"
                               @change="(val) => load_dataTab_index(val)">
                      <el-option label="请选择" value=0></el-option>
                      <el-option :label="item.label" :value=item.value :data="item" v-for="item in select_tables_options"
                                 v-bind:key="item.value"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :sm="12" :xs="12" :md="12" :lg="12" :xl="12">
                  <el-form-item label="1.2 标准数据索引">
                    <el-select v-model="FreeVDB.indexs" placeholder="标准数据表" size="small"
                               @change="(val) => handle_load(val)">
                      <el-option label="请选择" value=0></el-option>
                      <el-option :label="item.label" :value=item.value :data="item" v-for="item in select_index_options"
                                 v-bind:key="item.value"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row :gutter="10">
                <el-col :sm="12" :xs="12" :md="12" :lg="12" :xl="12">
                  <el-form-item label="2.1. 性別">
                    <el-input v-model="freelifeVDB.gender" placeholder="性別" size="small" :clearable="true" v-show="false"
                              :disabled="gender_dis"></el-input>
                    <el-radio-group v-model="freelifeVDB.gender" :disabled="gender_dis">
                      <el-radio :label="opt.value" v-for="opt in gender_options" v-bind:key="opt.key" @change="set_select_table">
                        {{ opt.label }}
                      </el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :sm="12" :xs="12" :md="12" :lg="12" :xl="12">
                  <el-form-item label="2.2. 吸煙者 (N/S)">
                    <el-input v-model="freelifeVDB.smoker" placeholder="分类名称" size="small" :clearable="true" v-show="false"
                              :disabled="smoker_dis"></el-input>
                    <el-radio-group v-model="freelifeVDB.smoker" :disabled="smoker_dis">
                      <el-radio :label="opt.value" v-for="opt in smoker_options" v-bind:key="opt.key" @change="set_select_table">
                        {{ opt.label }}
                      </el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :sm="12" :xs="12" :md="12" :lg="12" :xl="12">
                  <el-form-item label="2.3. GCV 表">
                    <el-switch v-model="freelifeVDB.gcv" active-text="on" size="small"
                               style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" @change="set_gvc_opt"/>
                  </el-form-item>
                </el-col>
                <el-col :sm="12" :xs="12" :md="12" :lg="12" :xl="12">
                  <el-form-item label="2.4. 供款期">
                    <el-select v-model="freelifeVDB.select_payment" style="width: 100px" placeholder="供款期" size="small"
                               @change="set_select_table">
                      <el-option label="请选择" value=0></el-option>
                      <el-option :label="item.label" :value=item.value :data="item" v-for="item in select_payment_options"
                                 v-bind:key="item.value"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-card>
        </el-col>
      </el-row>
    </div>
    <!--中部数据表格栏-->
    <div class="col-md-12" style="margin-top: 25px">
      <el-row :gutter="10">
        <el-col :span="22" :offset="1" class="clearfix">
          <el-card class="box-card" style="margin-bottom: 15px">
            <template #header>
              <div class="card-header">
                <span style="font-size: 22px;">B.年化产品标准值 </span>
              </div>
            </template>
            <div style="overflow:auto;overflow-x: hidden">
              <el-table :header-cell-style="{background: '#eef1f6', color:'#606266'}"
                        :data="tableData" :cell-style="{padding:'3px'}"
                        :row-style="{height:'30px'}" :max-height="tableHeight"
                        :key="isIndex" style="width: 100%" v-loading="isLoading" border stripe row-key="id">
                <el-table-column fixed type="index" label="序号" width="85px" v-show="false"></el-table-column>
                <el-table-column fixed prop="id" label="id"/>
                <el-table-column fixed prop="anb_index" label="ANB索引"/>
                <el-table-column fixed prop="year" label="年期"/>
                <el-table-column fixed prop="val" label="数值">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.val" style="width: 100px" placeholder="数值" size="small" :clearable="true"/>
                    <el-button type="danger" @click="handle_edit_val(scope.row)" size="small" style="margin-left: 15px">修正</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import {mapMutations} from "vuex";
import {initVDBParam, loadVDBStdTab} from "@/api/PurmFreelifeApi";
import {Message} from 'element-ui';

export default {
  name: "PurmFreelifeVDBView",
  components: {},
  data() {
    return {
      isIndex: 1,
      isLoading: false,
      tableHeight: 650,
      freelifeVDB: {
        gender: '-1',
        smoker: '-1',
        gcv: false,
        select_payment: 0,
      },
      FreeVDB: {
        tables: '',
        indexs: 0,
      },
      tableData: [],
      select_index_options: [],
      select_tables_options: [
        {label: "LFREE_10Y", value: "LFREE_10Y", key: "LFREE_10Y"},
        {label: "LFREE_10Y_GCV", value: "LFREE_10Y_GCV", key: "LFREE_10Y_GCV"},
        {label: "LFREE_1Y", value: "LFREE_1Y", key: "LFREE_1Y"},
        {label: "LFREE_1Y_GCV", value: "LFREE_1Y_GCV", key: "LFREE_1Y_GCV"},
        {label: "LFREE_20Y", value: "LFREE_20Y", key: "LFREE_20Y"},
        {label: "LFREE_20Y_GCV", value: "LFREE_20Y_GCV", key: "LFREE_20Y_GCV"},
        {label: "LFREE_30Y", value: "LFREE_30Y", key: "LFREE_30Y"},
        {label: "LFREE_30Y_GCV", value: "LFREE_30Y_GCV", key: "LFREE_30Y_GCV"},
        {label: "LFREE_F_NS", value: "LFREE_F_NS", key: "LFREE_F_NS"},
        {label: "LFREE_F_S", value: "LFREE_F_S", key: "LFREE_F_S"},
        {label: "LFREE_M_NS", value: "LFREE_M_NS", key: "LFREE_M_NS"},
        {label: "LFREE_M_S", value: "LFREE_M_S", key: "LFREE_M_S"},
      ],
      gender_options: [
        {label: "不计算", value: "-1", key: "-1"},
        {label: "男性", value: "M", key: "M"},
        {label: "女性", value: "F", key: "F"}
      ],
      gender_dis: false,
      smoker_options: [
        {label: "不计算", value: "-1", key: "-1"},
        {label: "吸煙者", value: "S", key: "S"},
        {label: "非吸煙者", value: "N", key: "N"}
      ],
      smoker_dis: false,
      select_payment_options: [
        {label: "1", value: "1", key: "1"},
        {label: "10", value: "10", key: "10"},
        {label: "20", value: "20", key: "20"},
        {label: "30", value: "30", key: "30"}
      ],
    }
  },
  computed: {},
  methods: {
    ...mapMutations(['add_tab']),
    handleFetch() {
      this.isLoading = true;
      this.handle_init();
    },
    handle_init() {
      this.tableData = [];
      this.select_index_options = [];
    },
    handle_load() {
      if (this.FreeVDB.tables == null || this.FreeVDB.tables.length == 0) {
        this.$notify({
          title: '错误',
          message: '请选择标准数据表',
          type: 'error',
          offset: 100
        });
        return;
      }
      if (this.FreeVDB.indexs == null || this.FreeVDB.indexs.length == 0 || this.FreeVDB.indexs == 0) {
        this.$notify({
          title: '错误',
          message: '请选择标准数据索引',
          type: 'error',
          offset: 100
        });
        return;
      }
      this.isLoading = true;
      this.tableData = [];
      loadVDBStdTab(this.FreeVDB).then(res => {
        let _res = eval(res.data);
        // 发起参数核算
        if (res.code == 200) {
          this.tableData = _res;
        }
        this.isLoading = false;
      }).catch(err => {
        Message.error('基础参数数据读取异常' + err);
      })
    },
    handle_edit_val(row) {
      this.isLoading = false;
      let editVDBObj = {tables: this.FreeVDB.tables, idx: row.id, val: row.val};
      this.open(editVDBObj);
    },
    load_dataTab_index(table_name) {
      this.select_index_options = [];
      this.FreeVDB.tables = table_name;
      initVDBParam(this.FreeVDB).then(res => {
        let _res = eval(res.data);
        // 发起参数核算
        if (res.code == 200) {
          this.select_index_options = _res;
          this.FreeVDB.indexs = 0;
        }
      }).catch(err => {
        Message.error('基础参数数据读取异常' + err);
      })
    },
    set_gvc_opt() {
      if (this.freelifeVDB.gcv) {
        this.gender_dis = true;
        this.smoker_dis = true;
      } else {
        this.gender_dis = false;
        this.smoker_dis = false;
      }
      this.set_select_table();
    },
    set_select_table() {
      this.FreeVDB.tables = ""
      if (this.freelifeVDB.gender == "-1" && this.freelifeVDB.smoker == "-1") {
        this.select_tables_options = [
          {label: "LFREE_1Y", value: "LFREE_1Y", key: "LFREE_1Y"},
          {label: "LFREE_1Y_GCV", value: "LFREE_1Y_GCV", key: "LFREE_1Y_GCV"},
          {label: "LFREE_10Y", value: "LFREE_10Y", key: "LFREE_10Y"},
          {label: "LFREE_10Y_GCV", value: "LFREE_10Y_GCV", key: "LFREE_10Y_GCV"},
          {label: "LFREE_20Y", value: "LFREE_20Y", key: "LFREE_20Y"},
          {label: "LFREE_20Y_GCV", value: "LFREE_20Y_GCV", key: "LFREE_20Y_GCV"},
          {label: "LFREE_30Y", value: "LFREE_30Y", key: "LFREE_30Y"},
          {label: "LFREE_30Y_GCV", value: "LFREE_30Y_GCV", key: "LFREE_30Y_GCV"},
        ]
        if (this.freelifeVDB.gcv) {
          this.select_tables_options = [
            {label: "LFREE_10Y_GCV", value: "LFREE_10Y_GCV", key: "LFREE_10Y_GCV"},
            {label: "LFREE_1Y_GCV", value: "LFREE_1Y_GCV", key: "LFREE_1Y_GCV"},
            {label: "LFREE_20Y_GCV", value: "LFREE_20Y_GCV", key: "LFREE_20Y_GCV"},
            {label: "LFREE_30Y_GCV", value: "LFREE_30Y_GCV", key: "LFREE_30Y_GCV"},
          ]
        }
        switch (this.freelifeVDB.select_payment) {
          case "1":
            if (this.freelifeVDB.gcv) {
              this.select_tables_options = [
                {label: "LFREE_1Y_GCV", value: "LFREE_1Y_GCV", key: "LFREE_1Y_GCV"},
              ]
            } else {
              this.select_tables_options = [
                {label: "LFREE_1Y", value: "LFREE_1Y", key: "LFREE_1Y"},
                {label: "LFREE_1Y_GCV", value: "LFREE_1Y_GCV", key: "LFREE_1Y_GCV"},]
            }
            break;
          case "10":
            if (this.freelifeVDB.gcv) {
              this.select_tables_options = [
                {label: "LFREE_10Y_GCV", value: "LFREE_10Y_GCV", key: "LFREE_10Y_GCV"},
              ]
            } else {
              this.select_tables_options = [
                {label: "LFREE_10Y", value: "LFREE_10Y", key: "LFREE_10Y"},
                {label: "LFREE_10Y_GCV", value: "LFREE_10Y_GCV", key: "LFREE_10Y_GCV"},]
            }
            break;
          case "20":
            if (this.freelifeVDB.gcv) {
              this.select_tables_options = [
                {label: "LFREE_20Y_GCV", value: "LFREE_20Y_GCV", key: "LFREE_20Y_GCV"},
              ]
            } else {
              this.select_tables_options = [
                {label: "LFREE_20Y", value: "LFREE_20Y", key: "LFREE_20Y"},
                {label: "LFREE_20Y_GCV", value: "LFREE_20Y_GCV", key: "LFREE_20Y_GCV"},]
            }
            break;
          case "30":
            if (this.freelifeVDB.gcv) {
              this.select_tables_options = [
                {label: "LFREE_30Y_GCV", value: "LFREE_30Y_GCV", key: "LFREE_30Y_GCV"},
              ]
            } else {
              this.select_tables_options = [
                {label: "LFREE_30Y", value: "LFREE_30Y", key: "LFREE_30Y"},
                {label: "LFREE_30Y_GCV", value: "LFREE_30Y_GCV", key: "LFREE_30Y_GCV"},]
            }
            break;
          default:
            break;
        }
      } else {
        if (this.freelifeVDB.gender == "M") {
          if (this.freelifeVDB.smoker == "-1") {
            this.select_tables_options = [
              {label: "LFREE_M_S", value: "LFREE_M_S", key: "LFREE_M_S"},
              {label: "LFREE_M_NS", value: "LFREE_M_NS", key: "LFREE_M_NS"},]
          } else {
            if (this.freelifeVDB.smoker == "S") {
              this.select_tables_options = [
                {label: "LFREE_M_S", value: "LFREE_M_S", key: "LFREE_M_S"},
              ]
            } else {
              this.select_tables_options = [
                {label: "LFREE_M_NS", value: "LFREE_M_NS", key: "LFREE_M_NS"},]
            }
          }
        } else if (this.freelifeVDB.gender == "F") {
          if (this.freelifeVDB.smoker == "-1") {
            this.select_tables_options = [
              {label: "LFREE_F_S", value: "LFREE_F_S", key: "LFREE_F_S"},
              {label: "LFREE_F_NS", value: "LFREE_F_NS", key: "LFREE_F_NS"},]
          } else {
            if (this.freelifeVDB.smoker == "S") {
              this.select_tables_options = [
                {label: "LFREE_F_S", value: "LFREE_F_S", key: "LFREE_F_S"},]
            } else if (this.freelifeVDB.smoker == "N") {
              this.select_tables_options = [
                {label: "LFREE_F_NS", value: "LFREE_F_NS", key: "LFREE_F_NS"},]
            }
          }
        } else {
          if (this.freelifeVDB.smoker == "S") {
            this.select_tables_options = [
              {label: "LFREE_F_S", value: "LFREE_F_S", key: "LFREE_F_S"},
              {label: "LFREE_M_S", value: "LFREE_M_S", key: "LFREE_M_S"},
            ]
          } else if (this.freelifeVDB.smoker == "N") {
            this.select_tables_options = [
              {label: "LFREE_F_NS", value: "LFREE_F_NS", key: "LFREE_F_NS"},
              {label: "LFREE_M_NS", value: "LFREE_M_NS", key: "LFREE_M_NS"},
            ]
          }
        }
      }
    },
    open(editVDBObj) {
      this.$confirm('此变更会影响标准值运算结果，确认变更数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        alert(JSON.stringify(editVDBObj));
        Message({
          type: 'success',
          message: 'Delete completed',
        })
      }).catch(() => {
        Message({
          type: 'info',
          message: 'Delete canceled',
        })
      })
    }
  }
  ,
  created() {
    // this.handle_init();
  }
  ,
  mounted() {
  }
  ,
}
</script>
<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.custRow {
  display: flex;
  margin-top: 5px;
  padding: 5px 5px 5px 5px;
}

.grid-content {
  border-radius: 2px; /*圆角处理*/
  min-height: 0px;
  background-color: #0c5460;
}
</style>